package com.handsome.状态模式;

import java.util.Random;

/**
 * @author niechun
 * @date 2023/3/26 16:45
 */
public class CanRaffleState implements State{

    RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    public void deduce() {
        System.out.println("已经扣除了积分");
    }

    @Override
    public boolean raffle() {
        System.out.println("正在抽奖，请稍等");
        Random random=new Random();
        int i = random.nextInt(10);
        if (i==0){
            activity.setState(activity.getDispenseState());
            return true;
        }
        System.out.println("未抽中");
        activity.setState(activity.getNoRaffleState());
        return false;
    }

    @Override
    public void dispensePrize() {
        System.out.println("不能发放奖品");
    }
}
